package com.nai365.nart.member.controller;

import com.nai365.nart.common.core.util.R;
import com.nai365.nart.member.entity.UserMoneyLog;
import com.nai365.nart.member.service.UserMoneyLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/userMoneyLog" )
@Api(value = " UserMoneyLog", tags = "用户交易明细")
public class UserMoneyLogController {

	private final UserMoneyLogService userMoneyLogService;
	/**
	 * 通过userId查询用户交易流水
	 * @param userId
	 * @return R
	 */
	@ApiOperation(value = "通过userId查询", notes = "通过id查询")
	@GetMapping("/{userId}" )
	public R<List<UserMoneyLog>> getByUserMoneyLog(@PathVariable("userId" ) Long userId) {
		List<UserMoneyLog>  userMoneyLogs =userMoneyLogService.findUserMoneyLogList(userId);
		return R.ok(userMoneyLogs);
	}

	/**
	 * 保存交易流水
	 * @param userMoneyLog
	 * @see { UserMoneyLog }
	 */
	@ApiOperation(value = "保存交易流水", notes = "保存交易流水")
	@PostMapping("saveUserMoneyLog")
	public R<Boolean> saveUserMoneyLog(@RequestBody UserMoneyLog userMoneyLog){
		Boolean issuccess=userMoneyLogService.saveUserMoneyLog(userMoneyLog);
		return R.ok(issuccess,"新增成功");
	}
}
